﻿app.factory('commonFactory', function ($rootScope, $http, $localStorage) {
    // factory returns an object
    // you can run some code before
    commonFactory = function () {
        $http.defaults.headers.post['token'] = $rootScope.user.SessionId;
    };

    commonFactory.getCountrys = function () {
        return $http.post($rootScope.APIUrl + "getCountryList");
    };
    commonFactory.getUserById = function (UserId) {
       return $http.post($rootScope.APIUrl + 'GetUserByID', { UserId: UserId })
    };
    commonFactory.GetPaymentMethod = function () {
        return $http.post($rootScope.APITransactionUrl + 'GetPaymentMethod')
    };
    commonFactory.GetNotPeddingWalletList = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'WalletsNotPeddingWalletUser', { UserId: UserId })
    };
    commonFactory.GetNotFundingWalletList = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'WalletsNotFundingWalletUser', { UserId: UserId })
    };    
    commonFactory.GetUserLevel = function () {
        return $http.post($rootScope.APIUrl + 'GetUserLevel')
    };
    commonFactory.CheckSession = function (SessionId) {
        return $http.post($rootScope.APIUrl + 'CheckSession', { session: SessionId })
    };    
    commonFactory.ClearSession = function (UserId) {
        return $http.post($rootScope.APIUrl + 'ClearSession', { UserId: UserId })
    };
    commonFactory.GetPinRate = function () {
        return $http.post($rootScope.PinManageAPI + 'GetPinRate')
    };
    commonFactory.prototype.GetDashboard = function () {
        //$http.defaults.headers.post['token'] = $localStorage.user.SessionId;
        return $http.post($rootScope.APITransactionUrl + 'GetDashboard')
    };
    commonFactory.checkTrucTiep = function (UserID) {
        return $http.post($rootScope.API + '/CN_TrucTiep/Check_CNTrucTiep', { UserID: UserID })
    }

    commonFactory.checkTrucTiepN = function (UserID) {
        return $http.post($rootScope.API + '/TrucTiep/Check_TrucTiep', { UserID: UserID })
    }
    commonFactory.getGPuser = function () {
        return $http.post($rootScope.API + '/CN_TrucTiep/getGPuser')
    }
    commonFactory.getUserReceiveWithRandom = function () {
        return $http.post($rootScope.APITransactionUrl + 'getUserReceiveWithRandom')
    }
    commonFactory.getListCashOutByUser = function (UserID) {
        return $http.post($rootScope.APITransactionUrl + 'getListCashOutByUser', { UserID: UserID })
    }
    commonFactory.getWalletDefault = function (UserID) {
        return $http.post($rootScope.APITransactionUrl + 'getOnlyWalletByUser', { UserID: UserID })
    }
    commonFactory.getTransactionByWithdraw = function (withdrawID) {
        return $http.post($rootScope.APITransactionUrl + 'getTransactionByWithdraw', { wdID: withdrawID })
    }
    commonFactory.getListPackage = function () {
        return $http.post($rootScope.APITransactionUrl + 'getListPackage')
    }
    commonFactory.addOrderNotProfit = function (UserID,Amount,PinCode) {
        return $http.post($rootScope.APITransactionUrl + 'addOrderNotProfit', { UserId: UserID, Amount : Amount,PinCode : PinCode })
    }
    commonFactory.getListOrderByUser = function (UserID) {
        return $http.post($rootScope.APITransactionUrl + 'getListOrderByUser', { UserId: UserID})
    }
    commonFactory.getOrderById = function (orderId) {
        return $http.post($rootScope.APITransactionUrl + 'getOrderById', { orderId: orderId })
    }
    commonFactory.getInforByUserLogin = function (id) {
        return $http.post($rootScope.APIUrl + 'getInfomationByUserLogin', { id: id })
    }
    commonFactory.countChildBinary = function (id) {
        return $http.post($rootScope.APIUrl + 'countChildBinary', { id: id })
    }
    commonFactory.Register = function (register) {
        return $http.post($rootScope.APIUrl + 'Signup', { register: register })
    }
    commonFactory.getDocument = function (id) {
        return $http.post($rootScope.APIUrl + 'getDocument', { id: id })
    }
    commonFactory.specifiedLeftRight = function (id) {
        return $http.post($rootScope.APIUrl + 'specifiedLeftRight', { id: id })
    }
    commonFactory.approveWithdraws = function (id) {
        return $http.post($rootScope.APITransactionUrl + 'approveWithdraws', { id: id })
    }
    commonFactory.checkTimerPayOrder = function (Id_Order) {
        return $http.post($rootScope.APITransactionUrl + 'checkTimerPayOrder', { Id_Order: Id_Order })
    }
    commonFactory.getListUser = function (id) {
        return $http.post($rootScope.APIUrl + 'getListUserExceptUserLogin', { id: id })
    }
    commonFactory.loadProvideOrder = function (Id) {
        return $http.post($rootScope.APITransactionUrl + 'loadProvideOrder', { orderId: Id })
    }
    commonFactory.loadProvideHelp = function (userId) {
        return $http.post($rootScope.APITransactionUrl + 'loadProvideHelp', { orderId: userId })
    }
    commonFactory.getListRoomCode = function (userRecieve) {
        return $http.post($rootScope.APITransactionUrl + 'getListRoomCodeByUserRecieve', { userRecieve: userRecieve })
    }
    commonFactory.showProvideOrderRecieve = function (roomCode, userRecieveId) {
        return $http.post($rootScope.APITransactionUrl + 'showProvideOrderRecieve', { roomCode: roomCode, userRecieveId: userRecieveId })
    }
    commonFactory.approveProvideOrder = function (provideOrderId, RoomCode) {
        return $http.post($rootScope.APITransactionUrl + 'approveProvideOrder', { provideOrderId: provideOrderId ,roomCode:RoomCode})
    }
    commonFactory.approveProvideOrder2 = function (provideOrderId, RoomCode) {
        return $http.post($rootScope.APITransactionUrl + 'approveProvideOrder2', { provideOrderId: provideOrderId, roomCode: RoomCode })
    }
    commonFactory.getBankList = function () {
        return $http.post($rootScope.APITransactionUrl + 'getBankList')
    }
    commonFactory.checkCountPin = function (userId) {
        return $http.post($rootScope.PinManageAPI + 'checkCountPin', { userId: userId })
    }
    commonFactory.getPinOfUser = function (userId) {
        return $http.post($rootScope.PinManageAPI + 'getPinOfUser', { userId: userId })
    };
    commonFactory.getPinForPH = function (userId) {
        return $http.post($rootScope.PinManageAPI + 'getPinForPH', { userId: userId })
    };
    commonFactory.pushPin = function (userId, pinvalue) {
        return $http.post($rootScope.PinManageAPI + 'pushPin', { userId: userId, pin: pinvalue })
    };
    commonFactory.getListPH = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getListPH', { userId: UserId })
    };
    commonFactory.getListGH = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getListGH', { userId: UserId })
    };
    commonFactory.getWalletPublic = function () {
        return $http.post($rootScope.APITransactionUrl + 'getWalletPublic')
    };
    commonFactory.countPH = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'countPH', { userId: UserId })
    };
    commonFactory.countGH = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'countGH', { userId: UserId })
    };
    commonFactory.getBank = function (userId) {
        return $http.post($rootScope.APIUrl + 'getBank', { userId: userId })
    };
    commonFactory.confirmTransferOrder = function (Id, Status) {
        return $http.post($rootScope.APITransactionUrl + 'confirmTransferOrder', { transId: Id, Status: Status })
    };
    commonFactory.findTransferOrderById = function (transId) {
        return $http.post($rootScope.APITransactionUrl + 'findTransferOrderById', { transId: transId })
    };
    commonFactory.createBadReport = function (transId, type, desc, actionType) {
        return $http.post($rootScope.APITransactionUrl + 'createBadReport', { transId: transId, type: type, desc: desc, actionType: actionType })
    };
    commonFactory.confirmTransferPH = function (transId) {
        return $http.post($rootScope.APITransactionUrl + 'confirmTransferPH', { transId: transId })
    };
    commonFactory.getParentById = function (userId) {
        return $http.post($rootScope.APIUrl + 'getParentById', { userId: userId })
    };
    commonFactory.getConfirmTransferPH = function (transId) {
        return $http.post($rootScope.APITransactionUrl + 'getConfirmTransferPH', { transId: transId })
    };
    commonFactory.getListProfit = function (userId) {
        return $http.post($rootScope.APITransactionUrl + 'getListProfit', { userId: userId })
    };
    commonFactory.getWallet = function (userId) {
        return $http.post($rootScope.APITransactionUrl + 'getWallet', { userId: userId })
    };
    commonFactory.getWalletById = function (userId,walletId) {
        return $http.post($rootScope.APITransactionUrl + 'getWalletById', { userId: userId, walletId: walletId })
    };
    commonFactory.createWithdraw = function (userId, amount) {
        return $http.post($rootScope.APITransactionUrl + 'createWithdraw', { userPull: userId, amount: amount })
    };
    commonFactory.getListWd = function (userId) {
        return $http.post($rootScope.APITransactionUrl + 'getListWd', { userId: userId })
    };
    return commonFactory;
});
app.factory('profileFactory', function ($rootScope, $http) {
    profileFactory = {};
    $http.defaults.headers.post['token'] = $rootScope.token;
    profileFactory.Edit = function (DataProfile) {
        return $http.post($rootScope.APIEditProfile, { user: DataProfile, LR: '' })        
    };
    profileFactory.changePassword = function (data) {
        return $http.post($rootScope.APIUrl + 'changePassword', { Data: data })
    };
    profileFactory.changePassword2 = function (data) {
        return $http.post($rootScope.APIUrl + 'changeSecondPassword', { Data: data })
    };
    return profileFactory;
});
app.factory('ManagerPackFactory', function ($rootScope, $http, $localStorage) {
    ManagerPackFactory = {};
    ManagerPackFactory.getOverview = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'GetManagerPack', { UserId: UserId })
    }
    ManagerPackFactory.getPackRuning = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'GetRunningPack', { UserId: UserId })
    }
    ManagerPackFactory.getPackExpires = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'GetExpiresPack', { UserId: UserId })
    }    
    ManagerPackFactory.addBuyPack = function (UserId, Data) {
        return $http.post($rootScope.APITransactionUrl + 'buyPack', { UserId: UserId, Amount: Data.Amount, WalletId: Data.Wallet })
    }
    ManagerPackFactory.choseWalletAddPack = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'WalletsForBuyPack', { UserId: UserId })
    }
    ManagerPackFactory.getListAmount = function () {
        return $http.post($rootScope.APITransactionUrl + 'GetListAmountBitcoin')
    }
    ManagerPackFactory.GetPackDetail = function (Id) {
        return $http.post($rootScope.APITransactionUrl + 'GetPackDetail', { Id: Id })
    }

    return ManagerPackFactory;
});
app.factory('WalletFactory', function ($rootScope, $http, $localStorage) {
    WalletFactory = {};
    //get list wallet information
    WalletFactory.getMyWallet = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'GetWallets', { UserId: UserId })
    }
    //get list pedding wallet
    WalletFactory.getPeddingCash = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getListWithDraw', { userid: UserId })
    }
    //get list pedding wallet
    WalletFactory.getCashoutCompleted = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getListWithDrawCompleted', { userid: UserId })
    }
    WalletFactory.getBuysShare = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getBuysShare', { UserId: UserId })
    }
    WalletFactory.getSellsShare = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getSellsShare', { UserId: UserId })
    }
    WalletFactory.GetWalletsHistory = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getShareTransaction', { UserId: UserId })
    }
    WalletFactory.getShareManager = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getShareManager', { UserId: UserId })
    }
    WalletFactory.getFeeConfig = function () {
        return $http.post($rootScope.APITransactionUrl + 'getFeeConfig');
    }
    WalletFactory.getWalletHistoryByUser = function (UserID) {
        return $http.post($rootScope.APITransactionUrl + 'getWalletHistoryByUser', { UserId: UserID ,WalletId:1});
    }
    WalletFactory.getWalletHistoryByUser = function (UserID) {
        return $http.post($rootScope.APITransactionUrl + 'getWalletHistoryByUser', { UserId: UserID, WalletId: 1 });
    }
    return WalletFactory;
})
app.factory('PaymentFactory', function ($rootScope, $http) {
    PaymentFactory = {};

    //get account perfect money information
    PaymentFactory.getAccountPerfectMoney = function (UserId) {
        return $http.post($rootScope.APITransactionUrl + 'getAccountPerfectMoney', { UserId: UserId })
    }
    
    PaymentFactory.processPerfectMoney = function (Data) {
        return $http.post($rootScope.APIUrl + 'processPerfectMoney', { data: Data });
    }

    PaymentFactory.getPerfectTransaction = function (Id) {
        return $http.post($rootScope.APITransactionUrl + 'getPerfectTransaction4Wweb', { Id: Id });
    }
    //$rootScope.APITransactionUrl + 'getPerfectTransaction', { Id: $stateParams.id }
    return PaymentFactory;
})
app.factory('NewsFactory', function ($rootScope, $http) {
    NewsFactory = {};
    NewsFactory.getListNews = function () {
        return $http.post($rootScope.APITransactionUrl + 'getListNews')
    }
    NewsFactory.getNewsDetail = function (id) {
        return $http.post($rootScope.APITransactionUrl + 'getNewsDetail', { Id: id })
    }    
    return NewsFactory;
})
app.factory("TreeFactory", function ($rootScope, $http) {
    TreeFactory = {};
    TreeFactory.getTree = function () {
        return $http.post($rootScope.TrucTiepAPI + 'TrucTiep/showTreeTrucTiep')
    }
    return TreeFactory;
})
app.factory("GianTiepTreeFactory", function ($rootScope, $http) {
    $http.defaults.headers.post['token'] = $rootScope.token;
    GianTiepTreeFactory = {};
    GianTiepTreeFactory.getTree = function () {
        return $http.post($rootScope.GianTiepAPI + 'CN_TrucTiep/showTreeCN_TrucTiep')
    }    
    return GianTiepTreeFactory;
})
app.factory("PinManageFactory", function ($rootScope, $http) {
    PinManageFactory = {};
    PinManageFactory.GetListCard = function (UserId) {       
        return $http.post($rootScope.PinManageAPI + 'GetListCard', { UserId: UserId })
    }
    PinManageFactory.AddPin = function (UserId, Amount, WalletId) {
        return $http.post($rootScope.PinManageAPI + 'processAddPin', { UserId: UserId, Amount: Amount, WalletId: WalletId })
    }
    PinManageFactory.getListPinByUserId = function (id) {
        return $http.post($rootScope.PinManageAPI + 'getListPinByUserId', { userId: id })
    }
    PinManageFactory.transferPin = function (pinId, userTo) {
        return $http.post($rootScope.PinManageAPI + 'TransferPin', { pinId: pinId, userTo: userTo })
    }
    PinManageFactory.transferPinOfQuantum = function (userSend, userTo, Quantum, Password2) {
        return $http.post($rootScope.PinManageAPI + 'TransferPinOfQuantum', { userSend: userSend, userRecieve: userTo, Quantum: Quantum, password2: Password2 })
    }
    PinManageFactory.getPinHistory = function (userId) {
        return $http.post($rootScope.PinManageAPI + 'getPinHistory', { userId: userId })
    };
    PinManageFactory.checkIsFirstForPin = function (userId) {
        return $http.post($rootScope.PinManageAPI + 'checkIsFirstForPin', { userId: userId })
    };
    PinManageFactory.getTimeWaitActivePinForPH = function (userId) {
        return $http.post($rootScope.PinManageAPI + 'getTimeWaitActivePinForPH', { userId: userId })
    };
    PinManageFactory.unlockUser = function (userId) {
        return $http.post($rootScope.PinManageAPI + 'unlockUser', { userId: userId })
    };
    return PinManageFactory;
})
app.factory("BitcoinFactory", function ($rootScope, $http) {

    BitcoinFactory = {};
    //get account
    BitcoinFactory.getAccountBitCoin = function (UserId, Amount, Id, orderId) {
        return $http.post($rootScope.BitcoinAPI + 'GetAccountBitcoin', { UserId: UserId, Amount: Amount, Id: Id, orderId: orderId })
    }
    BitcoinFactory.getAccountBitcoinForPin = function (UserId, Amount, Id) {
        return $http.post($rootScope.BitcoinAPI + 'GetAccountBitcoinForPin', { UserId: UserId, Amount: Amount, Id: Id})
    }
    BitcoinFactory.changeAmountTransaction = function (UserId, Id, Amount) {
        return $http.post($rootScope.BitcoinAPI + 'ChangeAmountTransaction', { UserId: UserId, Id:Id, Amount:Amount })
    }
    BitcoinFactory.CheckBitcoindPayment = function (Id) {
        return $http.post($rootScope.BitcoinAPI + 'CheckBitcoindPayment', { Id: Id})
    }

    BitcoinFactory.GetAccountBitcoinByUserId = function (UserId) {
        return $http.post($rootScope.BitcoinAPI + 'GetAccountBitcoinByUserId', { UserId: UserId })
    }
    BitcoinFactory.GetBitcointoUSDRate = function (Bitcoin) {
        return $http.post($rootScope.BitcoinAPI + 'BitcointoUSD', { bitcoin: Bitcoin })
    };
    BitcoinFactory.getBitcoinOfUserReceive = function (userRecieveID) {
        return $http.post($rootScope.BitcoinAPI + 'getBitcoinOfUserReceive', { UserId: userRecieveID })
    };
    return BitcoinFactory;
})

app.factory("CN_TructiepFactory", function ($rootScope, $http, $localStorage) {
    $http.defaults.headers.common['token'] = $localStorage.user.SessionId;
    CN_TructiepFactory = {};
    CN_TructiepFactory.getList = function (UserId) {
        return $http.post($rootScope.GianTiepAPI + '/getProvideRoom',{ UserId: UserId })
    }
    CN_TructiepFactory.addProvideRoom = function (Amount, WalletId, countFor) {
        return $http.post($rootScope.GianTiepAPI + '/addProvideRoom', { WalletId: WalletId, Amount: Amount, countFor: countFor })
    }
    CN_TructiepFactory.RequestProvideRoom = function (Amount, WalletId, countFor) {
        return $http.post($rootScope.GianTiepAPI + '/RequestProvideRoom', { WalletId: WalletId, Amount: Amount, countFor: countFor })
    }
    CN_TructiepFactory.onUserAdded = function (ChiDinhId, UserAssign) {
        return $http.post($rootScope.GianTiepAPI + '/assignUser', { ChiDinhId: ChiDinhId, register: UserAssign })
    }
    
    return CN_TructiepFactory;
})

